package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminInvoiceDetail;
import  com.ygqh.baby.mapper.AdminInvoiceDetailMapper;
import  com.ygqh.baby.service.AdminInvoiceDetailService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminInvoiceDetailExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminInvoiceDetailServiceImpl implements AdminInvoiceDetailService{
	
	@Autowired
	private AdminInvoiceDetailMapper adminInvoiceDetailMapper;
	
	@Override
	public List<AdminInvoiceDetail> find() {
		AdminInvoiceDetailExample example = new AdminInvoiceDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminInvoiceDetailMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminInvoiceDetailExample example = new AdminInvoiceDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminInvoiceDetailMapper.countByExample(example);
	}

	@Override
	public AdminInvoiceDetail findById(Long id) {
		return adminInvoiceDetailMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminInvoiceDetail adminInvoiceDetail) {
		return adminInvoiceDetailMapper.insertSelective(adminInvoiceDetail);
	}

	@Override
	public int update(AdminInvoiceDetail adminInvoiceDetail) {
		return adminInvoiceDetailMapper.updateByPrimaryKeySelective(adminInvoiceDetail);
		
		 
	}

	@Override
	public ResultSet<AdminInvoiceDetail> search(QueryInfo queryInfo,String q) {
		List<AdminInvoiceDetail>  list =  adminInvoiceDetailMapper.selectSuper(queryInfo, q);
		int count = adminInvoiceDetailMapper.countSuper(q);
		ResultSet<AdminInvoiceDetail> resultSet = new ResultSet<AdminInvoiceDetail>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminInvoiceDetailExample example = new AdminInvoiceDetailExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminInvoiceDetail record = new AdminInvoiceDetail();
		record.setStatus(DataStatus.Delete);

		return adminInvoiceDetailMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminInvoiceDetail adminInvoiceDetail) {
		int r = 0;
		if(adminInvoiceDetail.getId() != null) {
			r = this.update(adminInvoiceDetail);
		}else {
			r = this.save(adminInvoiceDetail);
		}
		return r;
	}
	@Override
	public List<AdminInvoiceDetail> findByInvoiceId(Long id) {
		AdminInvoiceDetailExample example = new AdminInvoiceDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andInvoiceIdEqualTo(id);
		return adminInvoiceDetailMapper.selectByExample(example);
	}

}

